/*
 * Copyright (C) 2008 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.bignippleboy.recordthelife.list;

import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.ListView;

import com.bignippleboy.recordthelife.LifeRecordActivity;
import com.bignippleboy.recordthelife.LifeRecordItem;
import com.bignippleboy.recordthelife.LifeRecordManager;
import com.bignippleboy.recordthelife.R;
import com.bignippleboy.recordthelife.adapter.ItemAdapter;
import com.bignippleboy.recordthelife.capture.RecordDetailsActivity;
import com.bignippleboy.recordthelife.constants.Constants;

/**
 * Activity which displays the list of images.
 */
public class ItemList extends ListActivity {

	private LifeRecordManager lifeRecordManager;
    
    @Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		Intent intent = new Intent();
		intent.setClass(ItemList.this,
				LifeRecordActivity.class);
		startActivity(intent);
		this.finish();
		super.onBackPressed();
	}

	@Override
    public void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        super.onCreate(savedInstanceState);
        lifeRecordManager = LifeRecordManager.getInstance();
        ListView listView = getListView();
        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View footer = inflater.inflate(R.layout.list_footer, listView, false);
        listView.addFooterView(footer, null, false);
        setListAdapter(new ItemAdapter(this));

        // Theme.Light sets a background on our list.
        listView.setBackgroundDrawable(null);
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        LifeRecordItem item = lifeRecordManager.getmLifeRecords().get(position);
        
        Intent i = new Intent(this, RecordDetailsActivity.class);
        i.putExtra(Constants.ROWID, item.getRowId());
        startActivity(i);
        this.finish();
    }   
    
    
}